<template>
  <div class="box4" ref="map">我是地图组件</div>
</template>
<script lang="ts">
export default {
  name: "Map",
};
</script>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import * as echarts from "echarts";
//引入中国地图的JSON数据
import chinaJSON from "./china.json";
let map = ref();
echarts.registerMap("china", chinaJSON as any);
onMounted(() => {
  let mychart = echarts.init(map.value);
  mychart.setOption({
    show: true,
    geo: {
      map: "china",
      roam: true,
      left: 150,
      top: 150,
      right: 150,
      zoom: 1.2,
      bottom: 0,
      label: {
        show: true,
        color: "white",
        fontSize: 18,
      },
      itemStyle: {
        color: {
          type: "linear",
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: "skyblue", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "blue", // 100% 处的颜色
            },
          ],
          global: false,
        },
        opacity: 0.6,
      },
      //地图高亮的效果
      emphasis: {
        itemStyle: {
          color: "red",
        },
        label: {
          fontSize: 40,
        },
      },
    },
    grid: {
      left: 0,
      top: 0,
      right: 0,
      bottom: 0,
    },
    series: [
      {
        type: "lines",
        data: [
          {
            coords: [
              [116.405285, 39.904989],
              [119.306239, 26.075302],
            ],
          },
          {
            coords: [
              [117.283042, 31.86119],
              [116.405285, 39.904989],
            ],
          },
          {
            coords: [
              [117.283042, 31.86119],
              [104.065735, 30.659462],
            ],
          },
          {
            coords: [
              [117.283042, 31.86119],
              [115.892151, 28.676493],
            ],
          },
          {
            coords: [
              [118.767413, 32.041544],
              [120.153576, 30.287459],
            ],
          },
          {
            coords: [
              [116.405285, 39.904989], // 起点
              [114.298572, 30.584355], // 终点
            ],
          },
        ],
        lineStyle: {
          color: "blue",
          width: 5,
          curveness: 0.1,
          opacity: 0.1,
        },
        effect: {
          show: true,
          symbol: "arrow",
          color: "white",
          symbolSize: 10,
        },
      },
    ],
  });
});
</script>

<style scoped></style>
